{template 'common/header'}
<style type="text/css">
.mui-table-view .mui-media-object{ max-width:115px!important;width:115px!important; height:85px;background-size:auto 100%!important;border-radius: 4px;}
.mui-card.mui-one .mui-card-content-inner{ padding:10px;}
.mui-card.mui-two:first-child{ margin-top:0px;}
.mui-card.mui-two .mui-card-header{ position:relative;}
.mui-card.mui-one .mui-card-header:after{ position:absolute;left:10px;right:10px;bottom:0;height:1px;background-color:#D9D9D9!important;content:"";-webkit-transform:scaleY(0.5);transform:scaleY(0.5);}
.mui-card.mui-two .mui-card-header,.mui-card.mui-one .mui-card-footer{ background:none;}
.mui-card.mui-two .mui-card-header img:first-child{ width: 28px!important;height: 28px!important;border-radius:100px;}
.mui-card.mui-two .mui-card-header .mui-media-body{ min-height:28px; max-height:28px; font-size:13px; line-height:2.3!important;overflow:hidden;margin-left:0;}
.mui-card.mui-two .mui-card-header .mui-media-body>span{ overflow:hidden; position:relative;}
.mui-card.mui-two .mui-card-header .mui-media-body i.mui-badge{ right:0; padding:5px 10px; padding-bottom:3px;}
.mui-card.mui-two .mui-card-header .mui-media-body i.mui-badge-orange{ background:#fff!important; color:#ff6f02!important;}
.mui-card.mui-two .mui-card-header .mui-media-body i.mui-badge-orange:after{content: " ";width: 200%;height: 200%;position: absolute;top: 0;left: 0;border: 1px solid #ff6f02;box-sizing: border-box;border-radius: 100px;-webkit-transform: scale(0.5);transform: scale(0.5);-webkit-transform-origin: 0 0;transform-origin: 0 0;}
.list-content{min-height:45%;}
</style>
{template 'common/nav'}
<div class="mui-content mui-project">
    <div class="mui-scroll-wrapper-ext">
    <div class="mui-scroll-ext">
        <div class="list-content"></div>
    </div>
    </div>
</div>
<script>
mui('#segmentedControl').on('tap', 'a',function() {
	console.log(this.getAttribute('href'));
	location.href = this.getAttribute('href');
})
//上拉加载活动列表
$(function(){
    var pageStart = 0,pageEnd = 0,totalpage=0,thispage = 1,thispages = 10;
    $('.mui-scroll-ext').dropload({
        scrollArea : $('.mui-content').find('.mui-scroll-wrapper-ext'),
		threshold : 50,
        loadDownFn : function(me){
            $.ajax({
                type: 'GET',
                url: "{php echo app_url('member/project/ajax')}&page="+thispage+"&psize="+thispages,
                dataType: 'json',
                success: function(data){
					var stime = new Date(),result='';
					totalpage = data.tpage;
					if (thispage > totalpage || data.tpage == 0){
						me.lock();// 锁定
						me.noData();// 无数据
					}
					if (data.tpage == 0){
						result = '<div class="no-orders-at-all">'
							+'<div class="head-block">'
							+'    <div class="blank-icon mui-ext-icon mui-icon-mhuodong"></div>'
							+'    <p class="hint mui-text-gray">暂无活动信息</p>'
							+'    <p class="recommend-hint"></p>'
							+'</div></div>';
						$('.mui-scroll-ext').html('');
						$('.mui-scroll-ext').append(result);
						me.resetload();
						return false;
					}
                    for(var i = 0; i < data.list.length; i++){
						joinstime = new Date(data.list[i].joinstime.replace("-", "/").replace("-", "/"));
						joinetime = new Date(data.list[i].joinetime.replace("-", "/").replace("-", "/"));
						starttime = new Date(data.list[i].starttime.replace("-", "/").replace("-", "/"));
						endtime   = new Date(data.list[i].endtime.replace("-", "/").replace("-", "/"));
						sToend1 = joinetime.format('MM月dd日 hh:mm');
						sToend2 = starttime.format('MM月dd日 hh:mm');//+'~'+endtime.format('MM月dd日 hh:mm')
						
						var joinnum   = parseInt(data.list[i].joinnum),
							quota     = parseInt(data.list[i].quota),
							trueread  = parseInt(data.list[i].falseread)+parseInt(data.list[i].trueread),
							showjoin  = parseInt(data.list[i].showjoin),
							aprice    = data.list[i].aprice,
							minaprice = data.list[i].minaprice,
							merchant  = data.list[i].merchant,
							show    = parseInt(data.list[i].show),
							review  = parseInt(data.list[i].review);
						switch(show){
							case 0:showsmsg = '<span class="mui-badge mui-pull-left">未启用</span>';break;
							case 1:showsmsg = '<span class="mui-badge mui-badge-success mui-pull-left">已启用</span>';break;
							default:;
						}
						switch(review){
							case 0:statusmsg = '<span class="mui-badge mui-pull-right">待审核</span>';break;
							case 1:statusmsg = '<span class="mui-badge mui-badge-orange mui-pull-right">已审核</span>';break;
							case 2:statusmsg = '<span class="mui-badge mui-badge-danger mui-pull-right">未通过</span>';break;
							default:;
						}
						
						if (stime > endtime){
							tpl_status = '<span class="mui-badge">活动结束</span>';
						}else{
							if (joinnum >= quota && quota > 0){
								tpl_status = '<span class="mui-badge mui-badge-danger">名额已满</span>';
							}else{
								tpl_status = joinstime > stime ? '<span class="mui-badge">还未开始</span>' : (stime>joinetime ? '<span class="mui-badge">报名结束</span>': '<span class="mui-badge mui-badge-orange">报名中</span>');
							}						
						}
						tpl_price = aprice > 0 || minaprice > 0 ?'<span class="mui-text-orange mui-rmb">'+(minaprice?minaprice+' 起':aprice)+'</span>':'<span class="mui-text-success">免费活动</span>';
						tpl_quota = (quota>0?'剩余 <em class="mui-text-orange">'+(quota-joinnum)+'</em>':'<em class="mui-text-orange">名额不限</em>');
						result+='<div class="mui-card mui-one mui-two">'
						+'	<div class="mui-card-header mui-card-media" style="padding:0;">'
						+'		<ul class="mui-table-view">'
                 		+'			<li class="mui-table-view-cell"><a class="mui-navigate-right" href="'+"{php echo app_url('activity/detail/display', array('actype'=>'member'))}&activityid="+data.list[i].id+'"><p>'+data.list[i].title+'</p></a></li>'
               			+'		</ul>'
						+'	</div>'
						+'	<div class="mui-card-content">'
						+'		<div class="mui-card-content-inner">'
						+'			<p class="mui-ellipsis-2 mui-small">'+data.list[i].intro+'</p>'
						+'          <p class="mui-ext-icon mui-icon-shizhong"> 开始时间：'+sToend2+' '+tpl_status+'</p>'
						+'          <p class="mui-ext-icon mui-icon-dingwei"> '+(data.list[i].hasonline==1?'线上活动':merchant.storename)+'</p>'
						+'		</div>'
						+'	</div>'
						+'    <div class="mui-card-footer">'
						+'        <span class="mui-text-gray">已报名 <em class="mui-text-orange">'+joinnum+'</em></span>'
						+'        <span class="mui-text-gray">'+tpl_quota+'</span>'
						+'        <span class="mui-text-gray"></span>'
						+'        <a class="mui-text-gray" href="'+"{php echo app_url('member/project/post')}&activityid="+data.list[i].id+'">编辑</a>'
						+'    </div>'
						+'</div>';
							
                    }
					$('.list-content').append(result);
					thispage++;
					// 每次数据加载完，必须重置
					me.resetload();
                },
                error: function(xhr, type){
                    // alert('Ajax error!');
                    // 即使加载出错，也得重置
                    me.resetload();
                }
            });
        }
    });
});


//获取单个活动参加的人数
function getParams(id) {
	var params;
	$.ajax({
		type: 'GET',
		url: "{php echo app_url('home/index/getparams')}&activityid="+id,
		dataType: 'json',
		async:false, 
		success: function(data){
			params = data;
		}
	});
	return params;
}

//格式化日期
Date.prototype.format = function(format) {
    var o = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S": this.getMilliseconds()
    }
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}
</script>
</body>
</html>
